home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / technical documentation / develop / develop issue 27 / develop issue 27 code / 3d game controls / source / inits.c < prev    next >
Encoding:
Text File  |  1996-06-29  |  4.3 KB  |  186 lines

  1. //--------------------------------------------------------------------------------------------
  2. //  Initialization Code
  3. //
  4. //      by Philip McBride
  5. //        parts taken from Apple DTS sample code
  6. //
  7. //--------------------------------------------------------------------------------------------
  8.  
  9.  
  10. #include <AppleEvents.h>
  11. #include <ToolUtils.h>
  12. #include <Resources.h>
  13. #include <menus.h>
  14. #include <PictUtil.h>
  15. #include <QDOffScreen.h>
  16. #include <Errors.h>
  17. #include "GameControls.h"
  18. #include "extern.h"
  19. #include "inits.h"
  20.  
  21. //--------------------------------------------------------------------------------------------
  22. //  Initialize the Toolbox
  23. //
  24. void InitializeToolbox(void)
  25. {
  26.     short            index ;
  27.     long            gestaltResponse;
  28.     short            numMoreMasters = 20;
  29.     Handle            menuBar = nil;
  30.         
  31.     InitGraf(&qd.thePort);
  32.     InitFonts();
  33.     InitWindows();
  34.     InitMenus();
  35.     TEInit();
  36.     InitDialogs(0L);
  37.     InitCursor();
  38.     MaxApplZone();
  39.     
  40.     SetZone(ApplicZone());
  41.     for( index = 1; index <= numMoreMasters; index++) MoreMasters();
  42.     
  43.     FlushEvents(everyEvent, 0);
  44.     
  45.     // Check for Drag and Drop
  46.     if ((Gestalt(gestaltDragMgrAttr, &gestaltResponse) != noErr) ||
  47.             (!(gestaltResponse & (1 << gestaltDragMgrPresent)))) 
  48.         {
  49.         StopAlert(kMyStopAlertID, 0L);
  50.         ExitToShell();
  51.         }
  52.         
  53.     // Check for QuickDraw 3D
  54.     if ((Gestalt(gestaltQD3D, &gestaltResponse) != noErr) ||
  55.             gestaltResponse == gestaltQD3DNotPresent)
  56.         {
  57.         StopAlert(kMyStopAlertID, 0L);
  58.         ExitToShell();
  59.         }
  60.  
  61.     // initialize menu stuff
  62.     
  63.     menuBar = GetNewMBar(kMyMenuBar);        // Read menus into menu bar
  64.     
  65.     if ( menuBar == nil )
  66.          ExitToShell();                        // if we dont have it then quit - your app 
  67.                                              // needs a dialog here
  68.  
  69.     SetMenuBar(menuBar);                    // Install menus
  70.     DisposHandle(menuBar);
  71.     
  72.     AddResMenu(GetMHandle(mApple), 'DRVR');    // Add DA names to Apple menu
  73.  
  74.     MyAdjustMenus() ;
  75.     DrawMenuBar();
  76. }
  77.  
  78. //--------------------------------------------------------------------------------------------
  79. //  Initialize Globals
  80. //
  81. void InitializeGlobals(void)
  82. {
  83.     gQuit = gQuitting = false;
  84.     
  85.     Q3Initialize();
  86. }
  87.  
  88. //--------------------------------------------------------------------------------------------
  89. //  Deallocate Globals
  90. //
  91. void DeallocateGlobals(void)
  92. {
  93.     Q3Exit();    
  94. }
  95.  
  96. //--------------------------------------------------------------------------------------------
  97. //  Adjust Menus
  98. //
  99. void MyAdjustMenus( void ) 
  100. {
  101.     WindowPtr            theWindow ;
  102.     MenuHandle            theMenu ;
  103.  
  104.     theWindow = FrontWindow() ;
  105.     
  106.     if( theWindow != nil ) {
  107.     
  108.         theMenu =  GetMHandle ( mFile ) ;
  109.         
  110.         EnableItem ( theMenu, iClose );
  111.                  
  112.     }
  113.     else {
  114.  
  115.         theMenu =  GetMHandle ( mFile ) ;
  116.  
  117.         DisableItem ( theMenu, iClose );
  118.     }
  119.     
  120.     DrawMenuBar() ;
  121. }
  122.  
  123. //--------------------------------------------------------------------------------------------
  124. //  Initialize Apple Events
  125. //
  126. void InitAEStuff( void ) 
  127. {
  128.     OSErr  err;
  129.     
  130.     // Set up the self-addressed descriptor record.
  131.     pSelfPSN.highLongOfPSN = 0;
  132.     pSelfPSN.lowLongOfPSN = kCurrentProcess;    // Use this instead of GetCurrentProcess
  133.     err = AECreateDesc(typeProcessSerialNumber,(Ptr)&pSelfPSN,
  134.                         sizeof(ProcessSerialNumber),&pSelfAddress);
  135.     
  136.     pnilDesc.descriptorType = typeNull;            // Initialize the global nil descriptor record.
  137.     pnilDesc.dataHandle = nil;
  138.     
  139.     RegisterMyEvents() ;                        // and finally register appleEvent handlers
  140. }
  141.  
  142. //--------------------------------------------------------------------------------------------
  143. //  Check if Supports Apple Events
  144. //
  145. Boolean SupportsAEVT(void)
  146. {
  147.     OSErr err;
  148.     long response;
  149.     
  150.     if (!myTrapAvailable(kGestaltTrap))
  151.         return false;
  152.     
  153.     err = Gestalt(gestaltAppleEventsAttr,&response);
  154.     if (err!=noErr)
  155.         return false;
  156.         
  157.     return (response && (response << gestaltAppleEventsPresent));
  158. }
  159.  
  160. //--------------------------------------------------------------------------------------------
  161. //  Register Apple Events
  162. //
  163. void RegisterMyEvents(void)
  164. {
  165.     OSErr err;
  166.     
  167.     if (!SupportsAEVT())
  168.         return;
  169.     
  170.     err = AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,NewAEEventHandlerProc(MyAEHandleOAPP),0L,false);
  171.     if (err!=noErr)
  172.         return;
  173.                 
  174.     err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,NewAEEventHandlerProc(MyAEHandleODOC),0L,false);
  175.     if (err!=noErr)
  176.         return;
  177.                 
  178.     err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,NewAEEventHandlerProc(MyAEHandlePDOC),0L,false);
  179.     if (err!=noErr)
  180.         return;
  181.                 
  182.     err = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,NewAEEventHandlerProc(MyAEHandleQUIT),0L,false);
  183.     if (err!=noErr)
  184.         return;            
  185. }
  186.